<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>基本对象定义</title>
</head>
<body>
<p>通过箭头函数简化代码</p>
<p> 箭头函数提供了一种更加简洁的函数书写方式。基本语法是：参数 => 函数体</p>
<script>
    let title="ES6从入门到学会";
    let price =25;
    let publish="东软出版社";

    let book={
        title,price,publish,
        toString(){
            console.log(`<<${this.title}>> is ${price}元`);//<<ES6从入门到学会>> is 25元
        }
    };
    book['lang']="简体中文";

    console.log(book);//{title: "ES6从入门到学会", price: 25, publish: "东软出版社", toString: ƒ, lang: "简体中文"}
    book.toString();
    console.log(book.toString());//undefined

    //属性的简洁表示法
    const age = 12;
    const name = "Amy";
    const person = {age, name};
    console.log(person);   //{age: 12, name: "Amy"}
    //等同于
    const person1 = {age: age, name: name};
    console.log(person1);//{age: 12, name: "Amy"}

    //方法名也可以简写

    const personal = {
        sayHi(){
            console.log("Hi");
        }
    };
    personal.sayHi();  //"Hi"
    //等同于
    const personal1 = {
        sayHi:function(){
            console.log("Hi");
        }
    };
    personal1.sayHi();//"Hi"
</script>
</body>
</html>
